home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 80 / XENIATGM80.iso / Goodies / Blood 2 / Source / data.z / MessageMgr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-02  |  27.5 KB  |  1,101 lines

  1. //----------------------------------------------------------
  2. //
  3. // MODULE  : MessageMgr.h
  4. //
  5. // PURPOSE : Blood 2 Messaging system
  6. //
  7. // CREATED : 10/22/97
  8. //
  9. //----------------------------------------------------------
  10.  
  11. #include "MessageMgr.h"
  12. #include "VKDefs.h"
  13. #include "SharedDefs.h"
  14. #include "stdio.h"
  15. #include "BloodClientShell.h"
  16.  
  17. CMessageMgr *g_pMessageMgr = DNULL;
  18. CCheatMgr    *g_pCheatMgr = DNULL;
  19.  
  20.  
  21. #define ENCRYPT_CHEATS    1    // SET THIS TO NON-ZERO BEFORE WE SHIP!!!
  22.  
  23. #if ENCRYPT_CHEATS
  24.  
  25. CCheatMgr::CheatInfo CCheatMgr::s_CheatInfo[] = {    // encrypted codes
  26.     { "T\\Q",            DFALSE },    // god mode toggle
  27.     { "XSN",            DFALSE },    // Monolith Productions kicks fucking ass!
  28.     { "NZZ\\",            DFALSE },    // full ammo
  29.     { "PYV]",            DFALSE },    // Clipping
  30.     { "URNYaUf",        DFALSE },    // Full health
  31.     { "dUR_RNZV",        DFALSE },    // Display current position
  32.     { "UVQRZR",            DFALSE },    // Stealth
  33.     { "ORRSPNXR",        DFALSE },    // Triple Damage
  34.     { "XVYYRZNYY",        DFALSE },    // Kill all ais
  35.     { "`]RRQb]",        DFALSE },    // Increase speed attribute
  36.     { "`a_\\[TR_",        DFALSE },    // Increase strength attribute
  37.     { "PNYRO",            DFALSE },
  38.     { "\\]URYVN",        DFALSE },
  39.     { "V`UZNRY",        DFALSE },
  40.     { "TNOOf",            DFALSE },
  41.     { "OR_RaaN",        DFALSE },    // Weapon pickup cheats
  42.     { "`bOZNPUV[RTb[",    DFALSE },
  43.     { "SYN_RTb[",        DFALSE },
  44.     { "`U\\aTb[",        DFALSE },
  45.     { "`[V]R__VSYR",    DFALSE },
  46.     { "U\\dVagR_",        DFALSE },
  47.     { "[N]NYZPN[[\\[",    DFALSE },
  48.     { "`V[TbYN_Vaf",    DFALSE },
  49.     { "N``NbYa_VSYR",    DFALSE },
  50.     { "ObTOb`aR_",        DFALSE },
  51.     { "ZV[VTb[",        DFALSE },
  52.     { "YN`R__VSYR",        DFALSE },
  53.     { "aR`YNPN[[\\[",    DFALSE },
  54.     { "c\\\\Q\\\\",        DFALSE },
  55.     { "aUR\\_O",        DFALSE },
  56.     { "YVSRYRRPU",        DFALSE },
  57.     { "PU\\`R[X[VSR",    DFALSE },        // ChosenKnife (Added by Andy 2/3/99)
  58. #ifdef _ADD_ON
  59.     { "P\\ZONa`U\\aTb[",DFALSE },        // CombatShotgun (Added by Andy 2/3/99)
  60.     { "SYNfR_",            DFALSE },        // Flayer (Added by Andy 2/3/99)
  61. #endif
  62.     { "T\\OYR",            DFALSE },
  63.     { "`P\\_]V\\",        DFALSE },
  64.     { "a\\aN_\\",        DFALSE },
  65.     { "`b]R_gbT",        DFALSE },        // demo level 2
  66.     { "T\\`U\\]]V[T",    DFALSE },        // give all inventory items
  67.     { "[VPR[b_`R",        DFALSE },        // health powerup
  68.     { "_RNYYf[VPR[b_`R",DFALSE },        // mega health powerup
  69.     { "dN_Q",            DFALSE },        // ward powerup
  70.     { "[RdP_\\dN_Q",    DFALSE },        // necroward powerup
  71.     { "PN_O\\[SVOR_",    DFALSE },        // invulnerability
  72.     { "aNXR\\SS`U\\R`",    DFALSE },        // stealth powerup
  73.     { "UR_XR_Zb_",        DFALSE },        // anger powerup
  74.     { "ORN[`\\SP\\\\Y[R``",DFALSE },    // god mode toggle 2 (different weapons)
  75.     { "S\\YY\\dZR",        DFALSE }        // Chase view
  76. };
  77.  
  78. #else
  79.  
  80. CCheatMgr::CheatInfo CCheatMgr::s_CheatInfo[] = {        // decrypted codes
  81.     { "GOD",            DFALSE },    // god mode toggle
  82.     { "KFA",            DFALSE },    // Monolith Productions kicks fucking ass!
  83.     { "AMMO",            DFALSE },    // full ammo
  84.     { "CLIP",            DFALSE },    // Clipping
  85.     { "HEALTHY",        DFALSE },    // Full health
  86.     { "WHEREAMI",        DFALSE },    // Display current position
  87.     { "HIDEME",            DFALSE },    // Invisibility
  88.     { "BEEFCAKE",        DFALSE },    // Triple Damage
  89.     { "KILLEMALL",        DFALSE },    // Kill all ais
  90.     { "SPEEDUP",        DFALSE },    // Increase speed attribute
  91.     { "STRONGER",        DFALSE },    // Increase strength attribute
  92.     { "CALEB",            DFALSE },
  93.     { "OPHELIA",        DFALSE },
  94.     { "ISHMAEL",        DFALSE },
  95.     { "GABBY",            DFALSE },
  96.     { "BERETTA",        DFALSE },    // Weapon pickup cheats
  97.     { "SUBMACHINEGUN",    DFALSE },
  98.     { "FLAREGUN",        DFALSE },
  99.     { "SHOTGUN",        DFALSE },
  100.     { "SNIPERRIFLE",    DFALSE },
  101.     { "HOWITZER",        DFALSE },
  102.     { "NAPALMCANNON",    DFALSE },
  103.     { "SINGULARITY",    DFALSE },
  104.     { "ASSAULTRIFLE",    DFALSE },
  105.     { "BUGBUSTER",        DFALSE },
  106.     { "MINIGUN",        DFALSE },
  107.     { "LASERRIFLE",        DFALSE },
  108.     { "TESLACANNON",    DFALSE },
  109.     { "VOODOO",            DFALSE },
  110.     { "THEORB",            DFALSE },
  111.     { "LIFELEECH",        DFALSE },
  112.     { "CHOSENKNIFE",    DFALSE },    // ChosenKnife (Added by Andy 2/3/99)
  113. #ifdef _ADD_ON
  114.     { "COMBATSHOTGUN",    DFALSE },    // CombatShotgun (Added by Andy 2/3/99)
  115.     { "FLAYER",            DFALSE },    // Flayer (Added by Andy 2/3/99)
  116. #endif
  117.     { "GOBLE",            DFALSE },
  118.     { "SCORPIO",        DFALSE },
  119.     { "TOTARO",            DFALSE },
  120.     { "SUPERZUG",        DFALSE },    // demo level 2
  121.     { "GOSHOPPING",        DFALSE },    // give all inventory items
  122.     { "NICENURSE",        DFALSE },    // health powerup
  123.     { "HOTNURSE",        DFALSE },    // mega health powerup
  124.     { "WARD",            DFALSE },    // ward powerup
  125.     { "NEWCROWARD",        DFALSE },    // necroward powerup
  126.     { "CARBONFIBER",    DFALSE },    // invulnerability
  127.     { "TAKEOFFSHOES",    DFALSE },    // stealth powerup
  128.     { "HERKERMUR",        DFALSE },    // anger powerup
  129.     { "BEANSOFCOOLNESS",DFALSE },    // god mode toggle 2 (different weapons)
  130.     { "FOLLOWME",        DFALSE }    // Chase view
  131. };
  132.  
  133. #endif
  134.  
  135.  
  136. // Externs...
  137.  
  138. extern    DBOOL    g_bLevelChange3rdPersonCam;
  139.  
  140.  
  141. // Statics...
  142.  
  143. DBOOL CCheatMgr::m_bPlayerCheated = DFALSE;
  144.  
  145.  
  146. // Prototypes...
  147.  
  148. DBOOL IsValidDemoCheat(int nCheat);
  149.  
  150.  
  151. // Functions...
  152.  
  153. /*******************************************************************************
  154.  
  155.     CMessageMgr
  156.  
  157. *******************************************************************************/
  158.  
  159. // ----------------------------------------------------------------------- //
  160. //
  161. //    ROUTINE:    CMessageMgr::CMessageMgr()
  162. //
  163. //    PURPOSE:    constructor
  164. //
  165. // ----------------------------------------------------------------------- //
  166.             
  167. CMessageMgr::CMessageMgr()
  168. {
  169.     g_pMessageMgr = this;
  170.     m_x    = 1;
  171.     m_y    = 0;
  172.  
  173.     m_nMaxMessages    = kDefaultMaxMessages;
  174.     m_fMessageTime    = kDefaultMessageTime;
  175.     m_dwMessageFlags = MESSAGEFLAGS_MASK;
  176.  
  177.     m_nMessageCount    = 0;
  178.     m_nFirstMessage    = 0;
  179.     m_nNextMessage    = m_nFirstMessage;
  180.     m_bEditing = DFALSE;
  181.  
  182.     m_hFont = DNULL;
  183. }
  184.  
  185.  
  186. // ----------------------------------------------------------------------- //
  187. //
  188. //    ROUTINE:    CMessageMgr::Init (CClientDE* pClientDE)
  189. //
  190. //    PURPOSE:    Initializes the Message manager
  191. //
  192. // ----------------------------------------------------------------------- //
  193.  
  194. DBOOL CMessageMgr::Init (CClientDE* pClientDE)
  195. {
  196.     if (!pClientDE) return DFALSE;
  197.  
  198.     m_pClientDE = pClientDE;
  199.     m_InputLine.Init(pClientDE);
  200.  
  201.     m_hFont = m_pClientDE->CreateFont("Arial", 6, 16, DFALSE, DFALSE, DFALSE);
  202.     m_nFontHeight = 16;
  203.  
  204.     return DTRUE;
  205. }
  206.  
  207.  
  208. // ----------------------------------------------------------------------- //
  209. //
  210. //    ROUTINE:    CMessageMgr::Enable()
  211. //
  212. //    PURPOSE:    Sets the enabled flag
  213. //
  214. // ----------------------------------------------------------------------- //
  215.             
  216. void CMessageMgr::Enable( DBOOL bEnabled )
  217. {
  218.     if (m_bEnabled && !bEnabled)
  219.         Clear();
  220.  
  221.     m_bEnabled = bEnabled;
  222. }
  223.  
  224.  
  225. // ----------------------------------------------------------------------- //
  226. //
  227. //    ROUTINE:    CMessageMgr::AddLine()
  228. //
  229. //    PURPOSE:    Adds a new line to the Message buffer
  230. //
  231. // ----------------------------------------------------------------------- //
  232.             
  233. void CMessageMgr::AddLine( char *szMsg, DBYTE uMessageFlag )
  234. {
  235.     if (szMsg)
  236.     {
  237.         HSTRING hString = m_pClientDE->CreateString(szMsg);
  238.         AddLine(hString, uMessageFlag);
  239.     }
  240. }
  241.  
  242. // ----------------------------------------------------------------------- //
  243. //
  244. //    ROUTINE:    CMessageMgr::AddLine()
  245. //
  246. //    PURPOSE:    Adds a new line to the Message buffer
  247. //
  248. // ----------------------------------------------------------------------- //
  249.             
  250. void CMessageMgr::AddLine( HSTRING hMsg, DBYTE uMessageFlag )
  251. {
  252.     // don't bother adding Messages disallowed by the user
  253.     if ( !(uMessageFlag && m_dwMessageFlags) )
  254.         return;
  255.  
  256.     HDECOLOR hForeground = m_pClientDE->SetupColor1 (1.0f, 1.0f, 1.0f, DFALSE);
  257.  
  258.     Message *pMsg = &m_Messages[ m_nNextMessage ];
  259.  
  260.     // Set next Message pointer
  261.     m_nNextMessage = (m_nNextMessage + 1) % kMaxMessages;
  262.  
  263.     // don't overflow the maximum number of Messages
  264.     if ( ++m_nMessageCount > m_nMaxMessages )
  265.     {
  266.         // expire the oldest Message and recalculate the first Message in the buffer
  267.         Message *pOld = &m_Messages[ m_nFirstMessage ];
  268.  
  269.         DeleteMessageData(pOld);
  270.  
  271.         m_nFirstMessage = (m_nFirstMessage + 1) % kMaxMessages;
  272.  
  273.         // reset the Message count to max
  274.         m_nMessageCount = m_nMaxMessages;
  275.     }
  276.  
  277.     pMsg->hSurface = m_pClientDE->CreateSurfaceFromString (m_hFont, hMsg, hForeground, NULL, 10, 0);
  278.     if (!pMsg->hSurface)  // Error
  279.     {
  280.         return;
  281.     }
  282.  
  283.     pMsg->hMessage = hMsg;
  284.     pMsg->fExpiration = m_pClientDE->GetTime() + m_fMessageTime;
  285.     
  286. }
  287.  
  288. // ----------------------------------------------------------------------- //
  289. //
  290. //    ROUTINE:    CMessageMgr::Draw()
  291. //
  292. //    PURPOSE:    Displays the Message list
  293. //
  294. // ----------------------------------------------------------------------- //
  295.             
  296. void CMessageMgr::Draw( void )
  297. {
  298.     if (!m_bEnabled)
  299.         return;
  300.  
  301.     // Try to draw a cheat message
  302.     DBOOL bDrawCheatMsg = DrawCheatMsg();
  303.  
  304.     // early return if there are no Messages in the queue,
  305.     // or Messages are disabled, or while typing Messages
  306.     if ( !m_bEditing && (m_nMessageCount == 0))
  307.         return;
  308.  
  309.     int nCount = m_nMessageCount;    // use temporary values
  310.     int nFirst = m_nFirstMessage;    // because the real ones may change
  311.     int i;
  312.     int y = m_y;
  313.  
  314.     if (bDrawCheatMsg) y += m_nFontHeight;
  315.  
  316.     HSURFACE hScreen = m_pClientDE->GetScreenSurface();
  317.  
  318.     for ( i = 0; i < nCount; i++)
  319.     {
  320.         Message *pMsg = &m_Messages[ (nFirst + i) % kMaxMessages ];
  321.  
  322.         // expire Messages that have overstayed their welcome
  323.         if ( m_pClientDE->GetTime() >= pMsg->fExpiration )
  324.         {
  325.             DeleteMessageData(pMsg);
  326.             // expire the oldest Message and recalculate the Message position and counter
  327.             m_nFirstMessage = (m_nFirstMessage + 1) % kMaxMessages;
  328.             m_nMessageCount--;
  329.  
  330.             // don't draw the expired Message
  331.             continue;
  332.         }
  333.  
  334.         // draw the text
  335.         m_pClientDE->DrawSurfaceToSurfaceTransparent (hScreen, pMsg->hSurface, NULL, m_x, y, NULL);
  336.         y += m_nFontHeight;
  337.     }
  338.  
  339.     if (m_bEditing)
  340.     {
  341.         HDECOLOR hForeground = m_pClientDE->SetupColor1 (1.0f, 1.0f, 1.0f, DFALSE);
  342.         m_InputLine.Draw(hScreen, m_hFont, hForeground, NULL, m_x, y);
  343.     }
  344. }
  345.  
  346.  
  347. // ----------------------------------------------------------------------- //
  348. //
  349. //    ROUTINE:    CMessageMgr::Draw()
  350. //
  351. //    PURPOSE:    Draws a cheat message if enabled
  352. //
  353. // ----------------------------------------------------------------------- //
  354.             
  355. DBOOL CMessageMgr::DrawCheatMsg( void )
  356. {
  357.     DBOOL bRetVal = DFALSE;
  358.     char szCheatString[200];
  359.  
  360.     _mbscpy((unsigned char*)szCheatString, (const unsigned char*)"");
  361.  
  362.     if (!m_bEnabled || !g_pCheatMgr || !m_pClientDE)
  363.         return bRetVal;
  364.  
  365.     if (g_pCheatMgr->s_CheatInfo[CHEAT_WHEREAMI].bActive)
  366.     {
  367.         DVector vPos;
  368.         VEC_INIT(vPos);
  369.  
  370.         HLOCALOBJ hClientObj = m_pClientDE->GetClientObject();
  371.         if (hClientObj)
  372.             m_pClientDE->GetObjectPos(hClientObj, &vPos);
  373.  
  374.         sprintf(szCheatString, "MY POS: X: %f, Y: %f, Z: %f", vPos.x, vPos.y, vPos.z);
  375.     }
  376.  
  377.     // Draw the message
  378.     if (_mbstrlen(szCheatString))
  379.     {
  380.         HDECOLOR hForeground = m_pClientDE->SetupColor1 (1.0f, 0.0f, 0.0f, DFALSE);
  381.         HSTRING hString = m_pClientDE->CreateString(szCheatString);
  382.         HSURFACE hSurface = m_pClientDE->CreateSurfaceFromString (m_hFont, hString, hForeground, NULL, 10, 0);
  383.  
  384.         m_pClientDE->DrawSurfaceToSurfaceTransparent (m_pClientDE->GetScreenSurface(), hSurface, NULL, m_x, m_y, NULL);
  385.  
  386.         m_pClientDE->DeleteSurface(hSurface);
  387.         m_pClientDE->FreeString(hString);
  388.         bRetVal = DTRUE;
  389.     }
  390.  
  391.     return bRetVal;
  392. }
  393.  
  394.  
  395. // ----------------------------------------------------------------------- //
  396. //
  397. //    ROUTINE:    CMessageMgr::Clear()
  398. //
  399. //    PURPOSE:    removes all Messages from the array
  400. //
  401. // ----------------------------------------------------------------------- //
  402.             
  403. void CMessageMgr::Clear( void )
  404. {
  405.     int i;
  406.     for ( i = 0; i < m_nMessageCount; i++)
  407.     {
  408.         Message *pMsg = &m_Messages[ (m_nFirstMessage + i) % kMaxMessages ];
  409.         DeleteMessageData(pMsg);
  410.     }
  411.  
  412.     m_nFirstMessage = m_nNextMessage = m_nMessageCount = 0;
  413. }
  414.  
  415.  
  416. // ----------------------------------------------------------------------- //
  417. //
  418. //    ROUTINE:    CMessageMgr::SetMaxMessages()
  419. //
  420. //    PURPOSE:    Sets the maximum number of Messages to display
  421. //
  422. // ----------------------------------------------------------------------- //
  423.             
  424. void CMessageMgr::SetMaxMessages( int nMaxMessages )
  425. {
  426.     if (nMaxMessages < 1) nMaxMessages = 1;
  427.     if (nMaxMessages > kMaxMessages) nMaxMessages = kMaxMessages;
  428.  
  429.     m_nMaxMessages = nMaxMessages;
  430. }
  431.  
  432.  
  433. void CMessageMgr::SetCoordinates( int x, int y )
  434. {
  435.     m_x = x;
  436.     m_y = y;
  437. }
  438.  
  439. void CMessageMgr::SetMessageTime( DFLOAT fSeconds )
  440. {
  441.     m_fMessageTime = fSeconds;
  442. }
  443.  
  444. void CMessageMgr::SetMessageFlags( DDWORD dwFlags )
  445. {
  446.     m_dwMessageFlags = dwFlags & MESSAGEFLAGS_MASK;
  447. }
  448.  
  449.  
  450. // ----------------------------------------------------------------------- //
  451. //
  452. //    ROUTINE:    CMessageMgr::HandleKeyDown()
  453. //
  454. //    PURPOSE:    Processes keystrokes
  455. //
  456. // ----------------------------------------------------------------------- //
  457.             
  458. DBOOL CMessageMgr::HandleKeyDown(int key, int rep)
  459. {
  460.     if (m_bEditing)
  461.         return m_InputLine.HandleKeyDown(key, rep);
  462.     else
  463.         return DFALSE;
  464. }
  465.  
  466.  
  467.  
  468. /*******************************************************************************
  469.  
  470.     CInputLine
  471.  
  472. *******************************************************************************/
  473.  
  474.  
  475. // ----------------------------------------------------------------------- //
  476. //
  477. //    ROUTINE:    CInputLine::Init (CClientDE* pClientDE)
  478. //
  479. //    PURPOSE:    Initializes the player Message
  480. //
  481. // ----------------------------------------------------------------------- //
  482.  
  483. void CInputLine::Init (CClientDE* pClientDE)
  484. {
  485.     m_pClientDE = pClientDE;
  486. }
  487.  
  488. // ----------------------------------------------------------------------- //
  489. //
  490. //    ROUTINE:    CInputLine::CInputLine()
  491. //
  492. //    PURPOSE:    constructor
  493. //
  494. // ----------------------------------------------------------------------- //
  495.             
  496. void CInputLine::Clear( void )
  497. {
  498.     *m_zText = '\0';    // nil the Message
  499.     m_nTextLen = 0;    // zero the length
  500. }
  501.  
  502.  
  503. // ----------------------------------------------------------------------- //
  504. //
  505. //    ROUTINE:    CInputLine::CInputLine()
  506. //
  507. //    PURPOSE:    constructor
  508. //
  509. // ----------------------------------------------------------------------- //
  510.             
  511. void CInputLine::Term( void )
  512. {
  513.     Clear();
  514.     g_pMessageMgr->SetEditingState(DFALSE);
  515.  
  516.     if (!g_bLevelChange3rdPersonCam)
  517.     {
  518.         m_pClientDE->SetInputState(DTRUE);
  519.     }
  520. }
  521.  
  522.  
  523. // ----------------------------------------------------------------------- //
  524. //
  525. //    ROUTINE:    CInputLine::CInputLine()
  526. //
  527. //    PURPOSE:    constructor
  528. //
  529. // ----------------------------------------------------------------------- //
  530.             
  531. void CInputLine::Draw(HSURFACE hDest, HDEFONT hFont, HDECOLOR hForeColor, HDECOLOR hBackColor, long x, long y)
  532. {
  533.     char zTemp[ MAXINPUTLINE + 2 ];
  534.     _mbscpy((unsigned char*)zTemp, (const unsigned char*)"SAY:");
  535.     _mbscat((unsigned char*)zTemp, (const unsigned char*)m_zText);
  536.  
  537.     double fTime = m_pClientDE->GetTime();
  538.     double tmp;
  539.  
  540.     fTime = modf(fTime, &tmp);
  541.     if (fTime > 0.5f)
  542.         _mbscat((unsigned char*)zTemp, (const unsigned char*)"_");    // add a cursor
  543.  
  544.     HSTRING hString = m_pClientDE->CreateString(zTemp);
  545.  
  546.     // Draws the string.
  547.     HSURFACE hSurface = m_pClientDE->CreateSurfaceFromString(hFont, hString, hForeColor, hBackColor, 0, 0);
  548.     m_pClientDE->DrawSurfaceToSurfaceTransparent(hDest, hSurface, NULL, x, y, hBackColor);
  549.     m_pClientDE->DeleteSurface(hSurface);
  550.     m_pClientDE->FreeString(hString);
  551. }
  552.  
  553.  
  554. // ----------------------------------------------------------------------- //
  555. //
  556. //    ROUTINE:    CInputLine::CInputLine()
  557. //
  558. //    PURPOSE:    constructor
  559. //
  560. // ----------------------------------------------------------------------- //
  561.             
  562. DBOOL CInputLine::AddChar( DBYTE ch )
  563. {
  564.     if (m_nTextLen < MAXINPUTLINE)    // space left in the Message
  565.     {
  566.         m_zText[m_nTextLen] = ch;    // add a character
  567.         m_nTextLen++;                // increment the length
  568.         m_zText[m_nTextLen] = '\0';    // terminate the string
  569.         return DTRUE;                // indicate success
  570.     }
  571.     return DFALSE;    // indicate failure
  572. }
  573.  
  574.  
  575. // ----------------------------------------------------------------------- //
  576. //
  577. //    ROUTINE:    CInputLine::CInputLine()
  578. //
  579. //    PURPOSE:    constructor
  580. //
  581. // ----------------------------------------------------------------------- //
  582.             
  583. void CInputLine::DelChar( void )
  584. {
  585.     if (m_nTextLen > 0)    // text in the Message?
  586.     {
  587.         m_nTextLen--;                // back up a character
  588.         m_zText[m_nTextLen] = '\0';    // terminate the string
  589.     }
  590. }
  591.  
  592.  
  593. // ----------------------------------------------------------------------- //
  594. //
  595. //    ROUTINE:    CInputLine::CInputLine()
  596. //
  597. //    PURPOSE:    constructor
  598. //
  599. // ----------------------------------------------------------------------- //
  600.             
  601. void CInputLine::Set( char *pzText )
  602. {
  603.     _mbsncpy((unsigned char*)m_zText, (const unsigned char*)pzText, MAXINPUTLINE);                    // copy the text
  604.     m_zText[MAXINPUTLINE] = '\0';                            // enforce null termination
  605.     m_nTextLen = _mbstrlen(pzText);                            // enforce max length
  606. }
  607.  
  608.  
  609. // ----------------------------------------------------------------------- //
  610. //
  611. //    ROUTINE:    CInputLine::CInputLine()
  612. //
  613. //    PURPOSE:    constructor
  614. //
  615. // ----------------------------------------------------------------------- //
  616.             
  617. void CInputLine::Send( void )
  618. {
  619.     // Send the Message to the server
  620.     HMESSAGEWRITE hMsg = m_pClientDE->StartMessage(CMSG_PLAYERMESSAGE);
  621.     m_pClientDE->WriteToMessageString(hMsg, m_zText);
  622.     m_pClientDE->EndMessage(hMsg);
  623.  
  624.     Term();
  625. }
  626.  
  627.  
  628. // ----------------------------------------------------------------------- //
  629. //
  630. //    ROUTINE:    CInputLine::CInputLine()
  631. //
  632. //    PURPOSE:    constructor
  633. //
  634. // ----------------------------------------------------------------------- //
  635.             
  636. DBOOL CInputLine::HandleKeyDown(int key, int rep)
  637. {
  638.     switch( key )
  639.     {
  640.         case VK_ESCAPE:
  641.             Term();
  642.             break;
  643.  
  644.         case VK_HOME:
  645.             Clear();
  646.             break;
  647.  
  648.         case VK_BACK:
  649.             DelChar();
  650.             break;
  651.  
  652.         case VK_SHIFT:
  653.             m_bShift = DTRUE;
  654.             break;
  655.  
  656.         case VK_RETURN:
  657.                 if ( g_pCheatMgr->Check(m_zText) )
  658.                     Term();
  659.                 else
  660.                     Send();
  661.             break;
  662.  
  663.         default:
  664.         {
  665.             char ch;
  666.             if (ch = AsciiXlate(key))
  667.             {
  668.                 if (!AddChar(ch) )
  669.                 {
  670.                 }
  671.             }
  672.             break;
  673.         }
  674.     }
  675.     return DTRUE;
  676. }
  677.  
  678.  
  679.  
  680. // ----------------------------------------------------------------------- //
  681. //
  682. //    ROUTINE:    CInputLine::HandleKeyUp()
  683. //
  684. //    PURPOSE:    Handles a key up Message, used for tracking shift keys
  685. //
  686. // ----------------------------------------------------------------------- //
  687.             
  688. void CInputLine::HandleKeyUp(int key)
  689. {
  690.     switch( key )
  691.     {
  692.         case VK_SHIFT:
  693.             m_bShift = DFALSE;
  694.             break;
  695.     }
  696. }
  697.  
  698.  
  699. // ----------------------------------------------------------------------- //
  700. //
  701. //    ROUTINE:    CInputLine::AsciiXlate()
  702. //
  703. //    PURPOSE:    Translates a VK_ code into something viewable.
  704. //
  705. // ----------------------------------------------------------------------- //
  706.             
  707. char CInputLine::AsciiXlate(int key)
  708. {
  709.     char ch = 0;
  710.     char *zNumShift = ")!@#$%^&*(";
  711.  
  712.     // Check for a letter
  713.     if (key >= VK_A && key <= VK_Z)
  714.     {
  715.         ch = m_bShift ? key : key - 'A' + 'a';
  716.     }
  717.     // Check for a number
  718.     else if (key >= VK_0 && key <= VK_9)
  719.     {
  720.         ch = m_bShift ? zNumShift[key - VK_0] : key;
  721.     }
  722.     // Now check for the remaining usable keys
  723.     else
  724.     {
  725.         switch(key)
  726.         {
  727.             case VK_SPACE: ch = ' '; break;
  728.             case 189: ch = m_bShift ? '_' : '-'; break;
  729.             case 187: ch = m_bShift ? '+' : '='; break;
  730.             case 219: ch = m_bShift ? '{' : '['; break;
  731.             case 221: ch = m_bShift ? '}' : ']'; break;
  732.             case 220: ch = m_bShift ? '|' : '\\'; break;
  733.             case 186: ch = m_bShift ? ':' : ';'; break;
  734.             case 222: ch = m_bShift ? '"' : '\''; break;
  735.             case 188: ch = m_bShift ? '<' : ','; break;
  736.             case 190: ch = m_bShift ? '>' : '.'; break;
  737.             case 191: ch = m_bShift ? '?' : '/'; break;
  738.         }
  739.     }
  740.     return ch;
  741.  
  742. }
  743.  
  744.  
  745.  
  746. /*******************************************************************************
  747.  
  748.     CCheatMgr
  749.  
  750. *******************************************************************************/
  751.  
  752. // ----------------------------------------------------------------------- //
  753. //
  754. //    ROUTINE:    CCheatMgr::Init()
  755. //
  756. //    PURPOSE:    Initializes the cheat manager
  757. //
  758. // ----------------------------------------------------------------------- //
  759.             
  760. void CCheatMgr::Init(CClientDE* pClientDE)
  761. {
  762.     m_pClientDE = pClientDE;
  763.     g_pCheatMgr = this;
  764.  
  765. #if ENCRYPT_CHEATS
  766.     Decrypt();
  767. #endif
  768.  
  769. }
  770.  
  771.  
  772. // ----------------------------------------------------------------------- //
  773. //
  774. //    ROUTINE:    CCheatMgr::Reset()
  775. //
  776. //    PURPOSE:    Resets all cheats to the off position
  777. //
  778. // ----------------------------------------------------------------------- //
  779.             
  780. void CCheatMgr::Reset()
  781. {
  782.     for (int i = 0; i < CHEAT_MAX; i++)
  783.     {
  784.         s_CheatInfo[i].bActive = DFALSE;
  785.     }
  786. }
  787.  
  788.  
  789. // ----------------------------------------------------------------------- //
  790. //
  791. //    ROUTINE:    CCheatMgr::Decrypt()
  792. //
  793. //    PURPOSE:    Decrypts the cheat codes
  794. //
  795. // ----------------------------------------------------------------------- //
  796.             
  797. void CCheatMgr::Decrypt()
  798. {
  799.     // Decrypt each cheat code...
  800.  
  801.     for (int i = 0; i < CHEAT_MAX; i++)
  802.     {
  803.         char* sCheat = s_CheatInfo[i].pzText;
  804.  
  805.         while (*sCheat != '\0' && *sCheat != NULL)
  806.         {
  807.             *sCheat -= 13;
  808.             sCheat++;
  809.         }
  810.     }
  811. }
  812.  
  813.  
  814. // ----------------------------------------------------------------------- //
  815. //
  816. //    ROUTINE:    CCheatMgr::Check()
  817. //
  818. //    PURPOSE:    See if a string is a cheat code
  819. //
  820. // ----------------------------------------------------------------------- //
  821.             
  822. DBOOL CCheatMgr::Check( char *pzText )
  823. {
  824.     char buf[MAXINPUTLINE+2];
  825.     unsigned i;
  826.  
  827.     // copy their text
  828.     _mbscpy((unsigned char*)buf, (const unsigned char*)pzText);
  829.     strupr(buf);
  830.  
  831.     // It should start with "MP"
  832.     if ( _mbsncmp((const unsigned char*)buf, (const unsigned char*)"MP", 2) != 0 )
  833.         return DFALSE;
  834.  
  835.     // convert it to cheat compatible text
  836. //    for ( i = 0; i < _mbstrlen(pzText); i++ )
  837. //        buf[i]++;
  838.  
  839.     // then compare the converted text (skip the first two chars, already know they are "MP"
  840.     for ( i = 0; i < CHEAT_MAX; i++ )
  841.     {
  842.         if ( _mbscmp((const unsigned char*) buf+2, (const unsigned char*)(s_CheatInfo[i].pzText) ) == 0)
  843.         {
  844.             Process( (CheatCodes)i );
  845.             return DTRUE;
  846.         }
  847.     }
  848.     return DFALSE;
  849. }
  850.  
  851.  
  852. // ----------------------------------------------------------------------- //
  853. //
  854. //    ROUTINE:    CCheatMgr::Process()
  855. //
  856. //    PURPOSE:    Calls the appropriate cheat function
  857. //
  858. // ----------------------------------------------------------------------- //
  859.             
  860. void CCheatMgr::Process( CheatCodes nCheatCode )
  861. {
  862.     // No cheats in multiplayer
  863.     if (g_pBloodClientShell && g_pBloodClientShell->IsMultiplayerGame())
  864.         return;
  865.  
  866.     if ( nCheatCode < CHEAT_NONE || nCheatCode >= CHEAT_MAX )
  867.         return;
  868.  
  869. #ifdef _DEMO
  870.     if (!IsValidDemoCheat(nCheatCode))
  871.     {
  872.         return;
  873.     }
  874. #endif
  875.  
  876.     // Weapon cheat
  877.     if ( nCheatCode >= CHEAT_FIRSTWEAPON && nCheatCode <= CHEAT_LASTWEAPON)
  878.     {
  879.         s_CheatInfo[nCheatCode].bActive = DTRUE;
  880.         // Tell the server
  881.         SendCheatMessage(nCheatCode, DTRUE);
  882.         return;
  883.     }
  884.  
  885.     // process cheat codes
  886.     switch ( nCheatCode )
  887.     {
  888.         case CHEAT_GOD:            // god mode toggle
  889.             ToggleCheat(nCheatCode, "You are a GOD.", "God mode off. Help!");
  890.             break;
  891.  
  892.         case CHEAT_KFA:            // god mode toggle
  893.             ActivateCheat(nCheatCode, "Monolith Rulez...");
  894.             break;
  895.  
  896.         case CHEAT_KFA2:        // god mode toggle (different weapons)
  897.             ActivateCheat(nCheatCode, "Monolith Rulez...");
  898.             break;
  899.  
  900.         case CHEAT_AMMO:        // full ammo
  901.             ActivateCheat(nCheatCode, "You have full ammo.");
  902.             break;
  903.  
  904.         case CHEAT_CLIP:        // toggle clipping mode
  905.             ToggleCheat(nCheatCode, "Spectator mode on.", "Spectator mode off.");    
  906.             break;
  907.  
  908.         case CHEAT_HEALTH:        // full health
  909.             ActivateCheat(nCheatCode, "You have full health.");
  910.             break;
  911.  
  912.         case CHEAT_WHEREAMI:    // Display position
  913.             ToggleCheat(nCheatCode, "Display pos on.", "Display pos off.");    
  914.             break;
  915.  
  916.         case CHEAT_STEALTH:        // Stealth mode
  917.             ActivateCheat(nCheatCode, "Where did I go??.");
  918.             break;
  919.  
  920.         case CHEAT_TRIPLEDAMAGE:    // Triple Damage
  921.             ActivateCheat(nCheatCode, "Beefcake! BEEFCAKE!");
  922.             break;
  923.  
  924.         case CHEAT_KILLALLAI:
  925.             ActivateCheat(nCheatCode, "...Let Tchernobog sort'em out.");
  926.             break;
  927.  
  928.         case CHEAT_INCSPEED:
  929.         case CHEAT_INCSTRENGTH:    // Increase strength
  930.         case CHEAT_CALEB:
  931.         case CHEAT_OPHELIA:
  932.         case CHEAT_ISHMAEL:
  933.         case CHEAT_GABRIELLA:
  934.             ActivateCheat(nCheatCode, DNULL);
  935.             break; 
  936.             
  937.         case CHEAT_GOBLE:
  938.         case CHEAT_SCORPIO:
  939.             ActivateCheat(nCheatCode, "Brian L. Goble is a programming god!");
  940.             break;
  941.  
  942.         case CHEAT_TOTARO:
  943.             ActivateCheat(nCheatCode, "Jim Totaro is da man!");
  944.             break;
  945.  
  946. #ifdef _DEMO
  947.         case CHEAT_DEMOLEVEL2:
  948.             g_pBloodClientShell->StartNewWorld("Demo_02", GAMETYPE_SINGLE, LOADTYPE_NEW_LEVEL);
  949.             break;
  950. #endif
  951.  
  952.         case CHEAT_GIVEALLINV:
  953.         {
  954.             ActivateCheat(nCheatCode, "You just bought our entire inventory!");
  955.             break;
  956.         }
  957.  
  958.         case CHEAT_POW_HEALTH:
  959.         {
  960.             ActivateCheat(nCheatCode, "Thanks nurse!");
  961.             break;
  962.         }
  963.             
  964.         case CHEAT_POW_MEGAHEALTH:
  965.         {
  966.             ActivateCheat(nCheatCode, "Thanks nurse! How bout a date?");
  967.             break;
  968.         }
  969.             
  970.         case CHEAT_POW_WARD:
  971.         {
  972.             ActivateCheat(nCheatCode, "Ward awarded");
  973.             break;
  974.         }
  975.             
  976.         case CHEAT_POW_NECROWARD:
  977.         {
  978.             ActivateCheat(nCheatCode, "Necroward awarded");
  979.             break;
  980.         }
  981.             
  982.         case CHEAT_POW_INVULN:
  983.         {
  984.             ActivateCheat(nCheatCode, "Light and strong");
  985.             break;
  986.         }
  987.             
  988.         case CHEAT_POW_STEALTH:
  989.         {
  990.             ActivateCheat(nCheatCode, "They'll never hear you coming");
  991.             break;
  992.         }
  993.             
  994.         case CHEAT_POW_ANGER:
  995.         {
  996.             ActivateCheat(nCheatCode, "...and the hurtfulness...");
  997.             break;
  998.         }
  999.  
  1000.         case CHEAT_CHASEVIEW:
  1001.         {
  1002.             ToggleCheat(nCheatCode, DNULL, DNULL);
  1003.             break;
  1004.         }
  1005.  
  1006.         default:
  1007.             return;                // skip setting global cheat indicator for unhandled cheats
  1008.     }
  1009.  
  1010.     m_bPlayerCheated = DTRUE;
  1011. }
  1012.  
  1013.  
  1014.  
  1015. // ----------------------------------------------------------------------- //
  1016. //
  1017. //    ROUTINE:    CCheatMgr::SendCheatMessage()
  1018. //
  1019. //    PURPOSE:    sends a cheat to the server
  1020. //
  1021. // ----------------------------------------------------------------------- //
  1022.             
  1023. void CCheatMgr::SendCheatMessage( CheatCodes nCheatCode, DBOOL bState )
  1024. {
  1025.     // Send the Message to the server
  1026.     HMESSAGEWRITE hMsg = m_pClientDE->StartMessage(CMSG_CHEAT);
  1027.     m_pClientDE->WriteToMessageByte(hMsg, (DBYTE)nCheatCode);
  1028.     m_pClientDE->WriteToMessageByte(hMsg, (DBYTE)bState);
  1029.     m_pClientDE->EndMessage(hMsg);
  1030. }
  1031.  
  1032.  
  1033.  
  1034. // ----------------------------------------------------------------------- //
  1035. //
  1036. //    ROUTINE:    CCheatMgr::ToggleCheat()
  1037. //
  1038. //    PURPOSE:    Generic cheat toggle function can be used for many cheats
  1039. //
  1040. // ----------------------------------------------------------------------- //
  1041.             
  1042. void CCheatMgr::ToggleCheat(CheatCodes nCheatCode, char *szMsgOn, char *szMsgOff)
  1043. {
  1044.     s_CheatInfo[nCheatCode].bActive = !s_CheatInfo[nCheatCode].bActive;
  1045.  
  1046.     if (s_CheatInfo[nCheatCode].bActive)
  1047.         g_pMessageMgr->AddLine(szMsgOn);
  1048.     else
  1049.         g_pMessageMgr->AddLine(szMsgOff);
  1050.  
  1051.     // Tell the server
  1052.     SendCheatMessage(nCheatCode, s_CheatInfo[nCheatCode].bActive);
  1053. }
  1054.  
  1055.  
  1056. // ----------------------------------------------------------------------- //
  1057. //
  1058. //    ROUTINE:    CCheatMgr::ActivateCheat()
  1059. //
  1060. //    PURPOSE:    Activates the given cheat code
  1061. //
  1062. // ----------------------------------------------------------------------- //
  1063.             
  1064. void CCheatMgr::ActivateCheat(CheatCodes eCheatCode, char *szMsgOn)
  1065. {
  1066.     s_CheatInfo[eCheatCode].bActive = DTRUE;
  1067.  
  1068.     // Tell the server
  1069.     SendCheatMessage(eCheatCode, DTRUE);
  1070.  
  1071.     if (szMsgOn)
  1072.         g_pMessageMgr->AddLine(szMsgOn);
  1073. }
  1074.  
  1075.  
  1076. // ----------------------------------------------------------------------- //
  1077. //
  1078. //    ROUTINE:    IsValidDemoCheat
  1079. //
  1080. //    PURPOSE:    Determines if the given cheat code is valid in the demo
  1081. //
  1082. // ----------------------------------------------------------------------- //
  1083.             
  1084. DBOOL IsValidDemoCheat(int nCheat)
  1085. {
  1086.     // Check if this is a valid cheat code...
  1087.  
  1088.     if (nCheat == CHEAT_GOD) return(DTRUE);
  1089.     if (nCheat == CHEAT_KFA) return(DTRUE);
  1090.     if (nCheat == CHEAT_WHEREAMI) return(DTRUE);
  1091.     if (nCheat == CHEAT_DEMOLEVEL2) return(DTRUE);
  1092.     if (nCheat == CHEAT_CLIP) return(DTRUE);
  1093.  
  1094.  
  1095.     // If we get here, it's not a valid cheat for the demo...
  1096.  
  1097.     return(DFALSE);
  1098. }
  1099.  
  1100.  
  1101.